package com.lhframework.sms.util;

import java.util.Random;

/**
 * Created by lh on 2017/7/8.
 */
public class RandomUtil {
    private static final int[] NUMBERS = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

    /**
     * 生成随机验证码
     *
     * @param length
     * @return
     */
    public static String verifyCode(int length) {
        StringBuilder verifyCode = new StringBuilder();
        for (int i = 0; i < length; i++) {
            int index = new Random().nextInt(NUMBERS.length);
            verifyCode.append(NUMBERS[index]);
        }
        return verifyCode.toString();
    }
}
